package com.watering.plan;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class PlantAdvice extends Activity {
	
	String plant;
	AutoCompleteTextView textView;
	Toast ts;
	
	public ArrayList<String> getPlants(){
		String[] list = null;
		ArrayList<String> plant = new ArrayList();
	    Base bs = new Base(this);
	    try{
				bs.createDataBase();
				bs.openDataBase();
				plant = bs.getPlantArray();
				bs.close();
		}catch(Exception e){
		}
		
		return plant;
		
	}
	
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
         setContentView(R.layout.plantadvice);
         
         ts =  Toast.makeText(this, R.string.plant_advice_help, Toast.LENGTH_SHORT);
         ts.setDuration(Toast.LENGTH_LONG);
         
         ImageView img = (ImageView)findViewById(R.id.helpbutton);
         img.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	ts.show();
	         }
	     });
         
         ArrayList<String> PLANTS = getPlants();
         
         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, PLANTS);
         textView = (AutoCompleteTextView)
                 findViewById(R.id.autocomplete);
         textView.setAdapter(adapter);
         
         
         
	     Button NewPlantButton = (Button) findViewById(R.id.Button01);
	     NewPlantButton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 plant = textView.getText().toString();
	        	 Intent myIntent = new Intent(PlantAdvice.this, ShowProfile.class);
	        	 myIntent.putExtra("plantname", plant );
		     	 startActivity(myIntent);

	         }
	     });
	}  
}